package com.qfedu.knowledge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.knowledge.dao.IQuestionNoteDao;
import com.qfedu.knowledge.entity.bo.NoteBO;
import com.qfedu.knowledge.entity.dto.AddNoteDTO;
import com.qfedu.knowledge.entity.dto.BasePageDTO;
import com.qfedu.knowledge.entity.vo.PageResult;
import com.qfedu.knowledge.service.IQuestionNoteService;
import com.qfedu.knowledge.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName QuestionNoteServiceImpl
 * @Author ykx
 * @Date 2024/4/30 17:18
 * @Version 1.0
 */
@Service
public class QuestionNoteServiceImpl extends ServiceImpl<IQuestionNoteDao, NoteBO> implements IQuestionNoteService {

    @Autowired
    private SecurityUtils securityUtils;

    @Override
    public Boolean takeNote(AddNoteDTO addNoteDTO) {
        NoteBO noteBO = new NoteBO();
        noteBO.setQuestionId(addNoteDTO.getQuestionId());
        noteBO.setNote(addNoteDTO.getNote());
        return save(noteBO);
    }

    @Override
    public PageResult<NoteBO> getNodeList(Long questionId, BasePageDTO basePageDTO) {
        Long userId = securityUtils.getCurrentUser().getId();
        QueryWrapper<NoteBO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("question_id", questionId);
        queryWrapper.eq("create_by", userId);
        PageHelper.startPage(basePageDTO.getPage(), basePageDTO.getSize());
        return new PageResult<>(new PageInfo<>(list(queryWrapper)));
    }
}
